--翎战为箭
local lingzhanweijian = fk.CreateSkill {
    name = "mcdh_lingzhanweijian",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

lingzhanweijian:addEffect('viewas',{
    pattern = "slash",
    card_filter = function(self, to_select, selected)
        return #selected == 0 and Fk:getCardById(to_select).suit == Card.Diamond
    end,
    view_as = function(self, cards)
        if #cards ~= 1  then return end
        local card = Fk:cloneCard("slash")
        card:addSubcard(cards[1])
        card.skillName = self.name
        return card
    end,
    enabled_at_response = function(self, player, response)
        return not response
    end,
})

lingzhanweijian:addEffect(fk.CardUsing,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and player == target
    end,
    on_cost = function(self, event, target, player, data)
        if data.card.trueName == "slash" then
            if player:getLostHp() > 0  then
                return true
            end
        elseif data.card.trueName == "jink" then
            if player:getLostHp() == 0  then
                return true
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        player:drawCards(1, self.name)
    end
})

lingzhanweijian:addEffect(fk.CardResponding,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and player == target
    end,
    on_cost = function(self, event, target, player, data)
        if data.card.trueName == "slash" then
            if player:getLostHp() > 0  then
                return true
            end
        elseif data.card.trueName == "jink" then
            if player:getLostHp() == 0  then
                return true
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        player:drawCards(1, self.name)
    end
})

lingzhanweijian:addEffect('targetmod',{
    bypass_distances =  function(self, player, skill, card, target)
        return  table.contains(card.skillNames, "mcdh_lingzhanweijian")
    end
})

Fk:loadTranslationTable {
    ["mcdh_lingzhanweijian"] = "翎战为箭",
    ["#mcdh_lingzhanweijian_trigger"] = "翎战为箭",
    [":mcdh_lingzhanweijian"] = "你可以将一张♦牌当做无距离限制的【杀】使用。你使用或打出【杀】/【闪】 时,若你已受伤/未受伤，你摸一张牌。",
}

return lingzhanweijian